package org.lee.basic.algorithm;

/**
 * @author jackielee
 * @version 1.0
 * @description Prime1
 * @date 2021/4/19
 */
public class Prime1 {
  public static void main(String[] args) {
    int m = 1;
    int n = 1000;
    int count = 0;
    // 质数 sqrt(n)
    for (int i = m; i < n; ++i) {
      if (isPrime(i)) {
        ++count;
        System.out.print(i + " ");
        if (count % 10 == 0) {
          System.out.println();
        }
      }
    }
    System.out.println();
    System.out.println("找到" + count);
  }

  private static boolean isPrime(int n) {
    if (n == 1) {
      return false;
    }
    for (int i = 2; i < Math.sqrt(n) + 1; ++i) {
      if ((n % i) == 0 || n == 1) {
        return false;
      }
    }
    return true;
  }
}
